package com.baseproject;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;

import static com.baseproject.util.Const.PURPOSE;
import static com.baseproject.util.Const.SHOW_LOGIN_LEVEL;
import static com.baseproject.util.Const.SHOW_ORDER_LEVEL;
import static com.baseproject.util.Const._RECEIVER_ACTION_NEED_LOGIN;
import static com.baseproject.util.Const._RECEIVER_ACTION_NEED_ORDER;

/**
 * Created by hp on 2017/6/10.
 */

public class BroadcastSender {

    public static void sendNeedLogin(Context context, String purpose, int showLoginLevel) {
        Intent intent = new Intent();
        intent.setAction(_RECEIVER_ACTION_NEED_LOGIN);
        intent.putExtra(PURPOSE, purpose);
        intent.putExtra(SHOW_LOGIN_LEVEL, showLoginLevel);

        sendBroadcast(context, intent);
    }

    public static void sendNeedOrder(Context context, String purpose, int showOrderLevel) {
        Intent intent = new Intent();
        intent.setAction(_RECEIVER_ACTION_NEED_ORDER);
        intent.putExtra(PURPOSE, purpose);
        intent.putExtra(SHOW_ORDER_LEVEL, showOrderLevel);

        sendBroadcast(context, intent);
    }

    private static void sendBroadcast(Context context, Intent intent) {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                context.sendBroadcast(intent);
            }
        });
    }
}
